using System.Windows.Forms;
using Belmost4PDA.Fasade;

namespace Belmost4PDA.Logic
{
    public class Mapper_RadioGroup:AbstractMapper
    {
        public Control_RadioGroup radioGroup = null;

        public Mapper_RadioGroup(Control_RadioGroup radioGroup)

        {
            this.radioGroup=radioGroup;
            SetValName(((PanelItem)(radioGroup.GetFormControl().Tag)).Caption);
        }

        public override void ToControls(DataRows.DataRows row)
        {
            foreach (RadioButton o in radioGroup.GetFormControl().Controls)
            {
                if (o.Tag.ToString().Equals(row.FieldByNameDef(FieldName(), "")))
                {
                    o.Checked = true;
                    SetInitValue(o.Tag.ToString());
                }
            };
        }

        public override bool IsKey()
        { 
            return false;
        }

        public override string FieldName()
        {
            return ((PanelItem)(radioGroup.GetFormControl().Tag)).FieldName;
        }

        public override string FieldVal()
        {
            string res = "";
            foreach (RadioButton o in radioGroup.GetFormControl().Controls)
            {
                if (o.Checked)
                {
                    res = o.Tag.ToString();
                    break;
                }
            }
            return res;
        }
    }
}
